package org.ohuang;


import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;

public class Main {




    public static void printlnReplaceConfig(String path){
        List<String> allPackage = SmaliUtilKt.findSimpleAllPageList(path);
        ArrayList<String> startWith = new ArrayList<>();
        startWith.add("/androidx");
        startWith.add("/android");
        startWith.add("/com/google");
        List<String> data=new ArrayList<>();
        allPackage.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                if (SmaliUtilKt.isMatch(s,startWith)){
                    data.add(s);
                }
            }
        });

        data.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                String[] split = s.split("/");
                StringBuilder stringBuilder=new StringBuilder();
                StringBuilder stringBuilder2=new StringBuilder();
                for (int i = 1; i < split.length; i++) {
                    stringBuilder.append(split[i]);
                    stringBuilder2.append(split[i]);
                    if (i==1){
                        stringBuilder.append("_ad");
                    }
                    stringBuilder.append("/");
                    stringBuilder2.append("/");
                }
                stringBuilder.delete(stringBuilder.length()-1,stringBuilder.length());
                stringBuilder2.delete(stringBuilder2.length()-1,stringBuilder2.length());
                System.out.println("\""+stringBuilder2.toString()+"\":"+"\""+stringBuilder.toString()+"\",");


            }
        });

        System.out.println("==============================");
        data.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                String[] split = s.split("/");
                StringBuilder stringBuilder=new StringBuilder();
                StringBuilder stringBuilder2=new StringBuilder();
                for (int i = 1; i < split.length; i++) {
                    stringBuilder.append(split[i]);
                    stringBuilder2.append(split[i]);
                    if (i==1){
                        stringBuilder.append("_ad");
                    }
                    stringBuilder.append(".");
                    stringBuilder2.append(".");
                }
                stringBuilder.delete(stringBuilder.length()-1,stringBuilder.length());
                stringBuilder2.delete(stringBuilder2.length()-1,stringBuilder2.length());
                System.out.println("\""+stringBuilder2.toString()+"\":"+"\""+stringBuilder.toString()+"\",");


            }
        });
    }

    public static void printlnReplaceConfig(String path,String path2){

        Set<String> allPackage = SmaliUtilKt.findAllPackage(path);
        List<String> twiter = SmaliUtilKt.findSimpleAllPageList(path2);
        List<String> data=new ArrayList<>();
        allPackage.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                if (SmaliUtilKt.isMatch(s,twiter)){
                    data.add(s);
                }
            }
        });

       List<String> data0=SmaliUtilKt.pageList2Simple(data);

        data0.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                String[] split = s.split("/");
                StringBuilder stringBuilder=new StringBuilder();
                StringBuilder stringBuilder2=new StringBuilder();
                for (int i = 1; i < split.length; i++) {
                    stringBuilder.append(split[i]);
                    stringBuilder2.append(split[i]);
                    if (i==1){
                        stringBuilder.append("_ad");
                    }
                    stringBuilder.append("/");
                    stringBuilder2.append("/");
                }
                stringBuilder.delete(stringBuilder.length()-1,stringBuilder.length());
                stringBuilder2.delete(stringBuilder2.length()-1,stringBuilder2.length());
                System.out.println("\""+stringBuilder2.toString()+"\":"+"\""+stringBuilder.toString()+"\",");


            }
        });

        System.out.println("==============================");
        data0.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                String[] split = s.split("/");
                StringBuilder stringBuilder=new StringBuilder();
                StringBuilder stringBuilder2=new StringBuilder();
                for (int i = 1; i < split.length; i++) {
                    stringBuilder.append(split[i]);
                    stringBuilder2.append(split[i]);
                    if (i==1){
                        stringBuilder.append("_ad");
                    }
                    stringBuilder.append(".");
                    stringBuilder2.append(".");
                }
                stringBuilder.delete(stringBuilder.length()-1,stringBuilder.length());
                stringBuilder2.delete(stringBuilder2.length()-1,stringBuilder2.length());
                System.out.println("\""+stringBuilder2.toString()+"\":"+"\""+stringBuilder.toString()+"\",");


            }
        });

    }

    public static void copyFileUsingFileStreams(File source, File dest)
            throws IOException {
        if (dest.getParentFile()!=null) {
            dest.getParentFile().mkdirs();
        }
        InputStream input = null;
        OutputStream output = null;
        try {
            input = new FileInputStream(source);
            output = new FileOutputStream(dest);
            byte[] buf = new byte[1024];
            int bytesRead;
            while ((bytesRead = input.read(buf)) > 0) {
                output.write(buf, 0, bytesRead);
            }
        } finally {
            if (input!=null) {
                input.close();
            }
            if (output!=null) {
                output.close();
            }
        }
    }

    public static List<String>  strings(String s){
        List<String> da=new ArrayList<>();
        String[] s1 = s.split(" ");
        for (int i = 0; i < s1.length; i++) {
            if (s1[i].startsWith("id/")){
                da.add(s1[i].replace("id/",""));
            }
        }
return da;
    }
}